package edu.nf.supermarket.web.controller.app;

import edu.nf.supermarket.base.BaseController;
import edu.nf.supermarket.entity.Coupon;
import edu.nf.supermarket.result.ResultVO;
import edu.nf.supermarket.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yjj
 * @date 2025-06-19
 */
@RestController
@RequestMapping("/activity")
public class ActivityCenterController extends BaseController {
    @Autowired
    private CouponService couponService;
    /**
     * 用户领取优惠卷
     */
    @RequestMapping("/addUserCoupon")
    public ResultVO<String> addUserCoupon(@RequestParam("userId") Integer userId,
                                          @RequestParam("couponId") Integer couponId) {
        couponService.addUserCoupon(userId, couponId, (byte) 0, LocalDateTime.now(), LocalDateTime.now().plusDays(7));
        return success("领取成功");
    }
    /**
     * 获取所有优惠卷
     */
    @RequestMapping("/findAllCoupons")
    public ResultVO<List<Coupon>> findAllCoupons() {
        return success(couponService.findAllCoupons());
    }
    /**
     * 获取用户拥有的优惠卷
     */
    @GetMapping("/findCouponByUserId")
    public ResultVO<List<Coupon>> findCouponByUserId(@RequestParam("userId") Integer userId){
        List<Coupon> couponByUserId = couponService.findCouponByUserId(userId);
        return success(couponByUserId);
    }
}
